const Mock = require('mockjs')
const Random = Mock.Random
const phonePrefix = ['132', '135', '189']
const index = Math.floor(Math.random() * phonePrefix.length)
var phone = phonePrefix[index] + Mock.mock(/\d{8}/)

const data = Mock.mock({
  'items|100': [{
    // id: '@increment',
    'id|+1': 1,
    name: '@first @last',
    // 性别
    'gender|1': ['F', 'M'],
    xh: Random.id(),
    sfz: Random.id(),
    email: '@email',
    phone: phone,
    address: `${Random.province()}-${Random.city()}-${Random.county()}`
  }]
})

module.exports = [
  {
    url: '/vue-admin-template/student/list',
    type: 'get',
    response: config => {
      const { page = 1, limit = 20, name } = config.query
      // const mockList = data.items
      const mockList = data.items.filter(item => {
        if (name && item.name.indexOf(name) < 0) return false
        return true
      })
      // [0-20)、
      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  },
  {
    url: '/vue-admin-template/student/update',
    type: 'post',
    response: config => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },
  {
    url: '/vue-admin-template/student/create',
    type: 'post',
    response: config => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]

